package com.blog.effective.note1;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;

/**
 * Created by 张俊强~ on 2017/10/27.
 */
public class EffectiveJavaDemoOne {

    public static void main(String[] args) {

        Boolean bool1 = Boolean.valueOf(true);
        Boolean bool2 = new Boolean(true);
        System.out.println(bool1.equals(bool2));
        System.out.println(bool1 == bool2);


        String str1 = "1qa2ws";
        String str2 = new String("1qa2ws");

        System.out.println(str1.equals(str2));      // 内容相等
        System.out.println(str1 == str2);             //地址不相等


        System.out.println("-----------BigInteger Test----------");
        int count = 1;
        while (count-- != 0) {
            BigInteger bi1 = BigInteger.probablePrime(4, new Random());
//            BigInteger bi1=new BigInteger(1,new Random());
            System.out.println(bi1);
        }

        System.out.println("-----------Singleton Test----------");
        MySingleton ms1 = MySingleton.newInstance();
        MySingleton ms2 = MySingleton.newInstance();

        System.out.println(ms1 == ms2);

        Map<Object, Object> hashMapObj = new HashMap();
        Map<Object, Object> treeMapObj = new TreeMap<Object, Object>();

    }

}

//public static<K,V> Map<K,V> getInstance(Object){
//    if(/*参数满足某某条件*/) {
//        return new HashMap<K, V>();
//    }
//    if(/*参数满足某某条件*/) {
//        return new TreeMap<K, V>();
//    }
//    /*……*/
//    /*等等等等*/
//}

class MySingleton {

    private static MySingleton mySingleton = null;

    public static MySingleton newInstance() {
        if (mySingleton == null) {
            MySingleton.mySingleton = new MySingleton();
        }
        return mySingleton;
    }
}

//    public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) {
//        Enum<?>[] universe = getUniverse(elementType);
//        if (universe == null)
//            throw new ClassCastException(elementType + " not an enum");
//
//        if (universe.length <= 64)  //如果长度小于64，则返回RegularEnumSet类型
//            return new RegularEnumSet<>(elementType, universe);
//        else                        //反之，返回JumboEnumSet类型
//            return new JumboEnumSet<>(elementType, universe);
//    }